package com.ss.android.article.base.feature.update.a;

import android.text.TextUtils;

import com.ss.android.account.model.SpipeUser;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.article.common.share.interf.IShareUpdateItemBean;
import com.ss.android.common.AbsApiThread;
import com.ss.android.image.model.ImageInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public final class d extends a implements IShareUpdateItemBean {
    private List<ImageInfo> A;
    private Map<String, Integer> B;
    private boolean C;
    public boolean a;
    public int b;
    public int c;
    public boolean d;
    public d e;
    private ArrayList<SpipeUser> f;
    private String g;
    private boolean h;
    private String u;
    private String v;
    private String w;
    private int x;
    private int y;
    private List<ImageInfo> z;

    public d(long arg2) {
        super(arg2);
        this.h = false;
        this.u = "";
        this.v = "";
        this.w = "";
        this.z = new ArrayList();
        this.A = new ArrayList();
        this.B = new HashMap();
        this.f = new ArrayList();
    }

    public final boolean a(JSONObject arg9) {
        JSONObject v4_2;
        JSONArray v4_1;
        int v5;
        JSONArray v0_2;
        JSONArray v3 = null;
        super.a(arg9);
        switch (this.p.e) {
            case 1: {
                break;
            }
            case 2: {
                return this.c(arg9);
            }
            default:
                return true;
        }

        boolean v0;
        try {
            this.d = AbsApiThread.optBoolean(arg9, "delete", false);
            if (!this.d) {
                if (arg9.has("user_digg")) {
                    this.a = AbsApiThread.optBoolean(arg9, "user_digg", false);
                }

                if (arg9.has("digg_count")) {
                    this.b = arg9.optInt("digg_count");
                }

                if (arg9.has("share_url")) {
                    this.w = arg9.optString("share_url");
                }

                if (arg9.has("comment_count")) {
                    this.c = arg9.optInt("comment_count");
                }

                if (arg9.has("comment_visible_count")) {
                    this.p.c = arg9.optInt("comment_visible_count");
                }

                if (arg9.has("digg_list")) {
                    v0_2 = arg9.optJSONArray("digg_list");
                } else {
                    v0_2 = v3;
                }
            } else {
                return true;
            }
            if (v0_2 != null) {
                this.p.g.clear();
                v5 = v0_2.length();
                int v4;
                for (v4 = 0; v4 < v5; ++v4) {
                    UserInfo v6 = UserInfo.fromJO(v0_2.optJSONObject(v4), true);
                    if (v6 != null) {
                        this.p.g.add(v6);
                    }
                }
            }

            if (arg9.has("comments")) {
                v4_1 = arg9.optJSONArray("comments");
            } else {
                v4_1 = v0_2;
            }
            if (v4_1 != null) {
                this.p.f.clear();
                v5 = v4_1.length();
                int v0_3;
                for (v0_3 = 0; v0_3 < v5; ++v0_3) {
                    c v6_1 = com.ss.android.article.base.feature.update.a.c.a(v4_1.optJSONObject(v0_3));
                    if (v6_1 != null) {
                        this.p.f.add(v6_1);
                    }
                }
            }

            if (arg9.has("digg_limit")) {
                this.p.d = arg9.optInt("digg_limit");
            }

            if (this.b < this.p.g.size()) {
                this.b = this.p.g.size();
            }

            if (this.c < this.p.f.size()) {
                this.c = this.p.f.size();
            }

            if (this.p.d < 0) {
                this.p.d = ArticleConstants.F;
            }

            JSONObject v0_4 = arg9.optJSONObject("origin_item");
            if (v0_4 != null && this.p.e == 1) {
                this.e = b(v0_4);
            }

            if (arg9.has("image_type")) {
                v4_2 = arg9.optJSONObject("image_type");
            } else {
                v4_2 = null;
            }

            if (v4_2 != null) {
                this.B.clear();
                Iterator v5_1 = v4_2.keys();
                while (v5_1 != null) {
                    if (!v5_1.hasNext()) {
                        break;
                    }

                    Object v0_5 = v5_1.next();
                    if (TextUtils.isEmpty(((CharSequence) v0_5))) {
                        continue;
                    }

                    int v6_2 = v4_2.optInt(((String) v0_5), 0);
                    if (v6_2 == 0) {
                        continue;
                    }

                    this.B.put((String) v0_5, Integer.valueOf(v6_2));
                }
            }

            if (arg9.has("origin_id")) {
                arg9.optLong("origin_id");
            }

            if (arg9.has("item_type")) {
                this.x = arg9.optInt("item_type");
            }

            if (arg9.has("forward_num")) {
                this.y = arg9.optInt("forward_num");
            }

            if (arg9.has("thumb_image_list")) {
                v4_1 = arg9.optJSONArray("thumb_image_list");
            } else {
                v4_1 = v3;
            }

            int v0_3;
            if (v4_1 != null) {
                this.z.clear();
                for (v0_3 = 0; v0_3 < v4_1.length(); ++v0_3) {
                    JSONObject v5_2 = v4_1.optJSONObject(v0_3);
                    if (v5_2 == null) {
                        break;
                    }

                    ImageInfo v5_3 = ImageInfo.fromJson(v5_2, false);
                    if (v5_3 != null) {
                        this.z.add(v5_3);
                    }
                }
            }

            if (arg9.has("large_image_list")) {
                v3 = arg9.optJSONArray("large_image_list");
            }

            if (v3 != null) {
                this.A.clear();
                for (v0_3 = 0; v0_3 < v3.length(); ++v0_3) {
                    v4_2 = v3.optJSONObject(v0_3);
                    if (v4_2 == null) {
                        break;
                    }

                    ImageInfo v4_3 = ImageInfo.fromJson(v4_2, false);
                    if (v4_3 != null) {
                        this.A.add(v4_3);
                    }
                }
            }

            if (arg9.has("is_admin")) {
                v0 = AbsApiThread.optBoolean(arg9, "is_admin", false);
                if (v0) {
                    this.C = v0;
                }
            }

            this.i();
            label_15:
            v0 = true;
        } catch (Exception v0_1) {
            v0_1.printStackTrace();
            v0 = false;
        }

        return v0;
    }

    public final JSONObject a() throws JSONException {
        JSONObject v0_2;
        Object v0_1;
        Iterator v4;
        JSONArray v1_1;
        JSONObject v3 = new JSONObject();
        v3.put("cell_type", this.p.e);
        v3.put("id", this.i);
        v3.put("type", this.j);
        v3.put("create_time", this.s);
        v3.put("is_pgc_author", this.t);
        v3.put("modify_time", this.modifyTime);
        v3.put("content", this.k);
        v3.put("device_type", this.m);
        v3.put("device_model", this.n);
        String v1 = "user_digg";
        int v0 = this.a ? 1 : 0;
        v3.put(v1, v0);
        v3.put("digg_count", this.b);
        v3.put("comment_count", this.c);
        v3.put("comment_visible_count", this.p.c);
        v3.put("action_desc", this.l);
        v3.put("share_url", this.w);
        if (this.o != null) {
            v3.put("user", this.o.toJson());
        }

        if (!this.p.g.isEmpty()) {
            v1_1 = new JSONArray();
            v4 = this.p.g.iterator();
            while (v4.hasNext()) {
                v1_1.put(((UserInfo) v4.next()).toJson());
            }

            v3.put("digg_list", v1_1);
        }

        if (!this.p.f.isEmpty()) {
            v1_1 = new JSONArray();
            v4 = this.p.f.iterator();
            while (v4.hasNext()) {
                v0_1 = v4.next();
                JSONObject v5 = new JSONObject();
                v5.put("id", ((c) v0_1).a);
                v5.put("create_time", ((c) v0_1).b);
                v5.put("content", ((c) v0_1).c);
                v5.put("is_pgc_author", ((c) v0_1).i);
                if (((c) v0_1).d != null) {
                    v5.put("user", ((c) v0_1).d.toJson());
                }

                if (((c) v0_1).e != null) {
                    v5.put("reply_user", ((c) v0_1).e.toJson());
                }

                if (((c) v0_1).f > 0) {
                    v5.put("reply_id", ((c) v0_1).f);
                }

                if (((c) v0_1).g > 0) {
                    v5.put("digg_count", ((c) v0_1).g);
                }

                v5.put("user_digg", ((c) v0_1).h);
                v1_1.put(v5);
            }

            v3.put("comments", v1_1);
        }

        v3.put("digg_limit", this.p.d);
        v3.put("delete", this.d);
        if (this.e != null) {
            v3.put("origin_id", this.e.i);
            v3.put("origin_item", this.e.a());
        }

        v3.put("item_type", this.x);
        v3.put("forward_num", this.y);
        if (!this.B.isEmpty()) {
            JSONObject v4_1 = new JSONObject();
            Iterator<Entry<String, Integer>> v5_1 = this.B.entrySet().iterator();
            while (v5_1.hasNext()) {
                Entry<String, Integer> next = v5_1.next();
                if (TextUtils.isEmpty(next.getKey())) {
                    continue;
                }

                v4_1.put(next.getKey(), next.getValue());
            }

            v3.put("image_type", v4_1);
        }

        if (!this.z.isEmpty()) {
            v1_1 = new JSONArray();
            v4 = this.z.iterator();
            while (v4.hasNext()) {
                v0_2 = ((ImageInfo) v4.next()).toJsonObj();
                if (v0_2 == null) {
                    continue;
                }

                v1_1.put(v0_2);
            }

            v3.put("thumb_image_list", v1_1);
        }

        if (!this.A.isEmpty()) {
            v1_1 = new JSONArray();
            v4 = this.A.iterator();
            while (v4.hasNext()) {
                v0_2 = ((ImageInfo) v4.next()).toJsonObj();
                if (v0_2 == null) {
                    continue;
                }

                v1_1.put(v0_2);
            }

            v3.put("large_image_list", v1_1);
        }

        if (this.C) {
            v3.put("is_admin", 1);
        }

        return v3;
    }

    public final void a(d arg5) {
        if (this != arg5) {
            if (arg5 != null && arg5 != this) {
                ((a) this).s = ((a) arg5).s;
                ((a) this).o = ((a) arg5).o;
                ((a) this).j = ((a) arg5).j;
                ((a) this).k = ((a) arg5).k;
                ((a) this).l = ((a) arg5).l;
                ((a) this).m = ((a) arg5).m;
                ((a) this).n = ((a) arg5).n;
                ((a) this).modifyTime = ((a) arg5).modifyTime;
                ((a) this).t = ((a) arg5).t;
                if (((a) this).r < ((a) arg5).r) {
                    ((a) this).r = ((a) arg5).r;
                }
            }

            this.a = arg5.a;
            this.b = arg5.b;
            this.c = arg5.c;
            this.w = arg5.w;
            this.g = arg5.g;
            this.f.clear();
            this.f.addAll(arg5.f);
            this.h = arg5.h;
            this.u = arg5.u;
            this.v = arg5.v;
            this.e = arg5.e;
            this.A.clear();
            this.A.addAll(arg5.A);
            this.z.clear();
            this.z.addAll(arg5.z);
            this.B.clear();
            this.B.putAll(arg5.B);
            this.x = arg5.x;
            this.y = arg5.y;
            if (arg5.C) {
                this.C = arg5.C;
            }

            this.p = arg5.p;
            this.i();
        }
    }

    public static d b(JSONObject arg6) {
        d v0 = null;
        if (arg6 != null) {
            long v2 = arg6.optLong("id");
            if (v2 > 0) {
                d v1 = new d(v2);
                if (v1.a(arg6)) {
                    v0 = v1;
                }
            }
        }

        return v0;
    }

    public final List b() {
        return this.z;
    }

    private boolean c(JSONObject arg8) {
        d v3;
        boolean v0_2;
        d v0_1;
        boolean v1 = true;
        this.g = arg8.optString("title");
        JSONObject v0 = arg8.optJSONObject("show_more");
        if (v0 == null) {
            v0_1 = this;
            v3 = v0_1;
            v0_2 = false;
        } else {
            this.u = v0.optString("url");
            this.v = v0.optString("text");
            if (!android.support.design.a.isTextEmpty(this.v) && !android.support.design.a.isTextEmpty(this.u)) {
                v0_2 = true;
                v3 = this;
            } else {
                v0_1 = this;
                v3 = v0_1;
                v0_2 = false;
            }
        }

        v3.h = v0_2;
        this.f.clear();
        JSONArray v5 = arg8.optJSONArray("user_list");
        int v0_3 = v5 != null ? v5.length() : 0;
        int v4;
        for (v4 = 0; v4 < v0_3; ++v4) {
            JSONObject v3_1 = v5.optJSONObject(v4);
            if (v3_1 != null) {
                try {
                    SpipeUser v3_3 = SpipeUser.parseUser(v3_1);
                    if (v3_3 == null) {
                        continue;
                    }

                    this.f.add(v3_3);
                } catch (JSONException v3_2) {
                    v3_2.printStackTrace();
                }
            }
        }

        if (this.f.isEmpty()) {
            v1 = false;
        }

        return v1;
    }

    public final String c() {
        String v0 = this.o != null ? this.o.avatarUrl : null;
        return v0;
    }

    public final int d() {
        return AppData.getInstance().useImageQqShare;
    }

    public final String e() {
        return this.k;
    }

    public final int getItemType() {
        return this.x;
    }

    public final long getId() {
        return this.i;
    }

    public final String getShareUrl() {
        return this.w;
    }

    public final String h() {
        String v0 = this.o != null ? this.o.screenName : null;
        return v0;
    }

    private void i() {
        int v1_1;
        Object v1;
        if (!this.B.isEmpty()) {
            Iterator v3 = this.z.iterator();
            while (v3.hasNext()) {
                Object v0 = v3.next();
                if ((this.B.isEmpty()) || v0 == null || (TextUtils.isEmpty(((ImageInfo) v0).mUri))) {
                    v1_1 = 0;
                } else {
                    Iterator v4 = this.B.entrySet().iterator();
                    do {
                        if (v4.hasNext()) {
                            v1 = v4.next();
                            if (!((ImageInfo) v0).mUri.equals(((Map.Entry) v1).getKey())) {
                                continue;
                            }
                            v1_1 = ((Integer) ((Map.Entry) v1).getValue()).intValue();
                        } else {
                            v1_1 = 0;
                        }
                        break;
                    }
                    while (true);


                }
                boolean v1_2 = v1_1 == 2 ? true : false;
                ((ImageInfo) v0).mIsGif = v1_2;
            }
        }
    }
}

